GATE Exam  >  GATE Questions  >  Consider the below given C program :#include#... Start Learning for Free
Consider the below given C program :
#include
#include
enum {false, true};
int main()
{
int i = 1;
do
{
printf("%d\n", i);
i++;
if (i < 15)
continue;
} while (false);
getchar();
return 0;
}
How many times the print statement is executed _________.
  • a)
    2
  • b)
    1
  • c)
    4
  • d)
    3
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Consider the below given C program :#include#includeenum {false, true}...
The do while loop checks condition after each iteration. So after the continue statement, control transfers to the statement while(false). Since the condition is false ‘i’ is printed only once.
View all questions of this test
Most Upvoted Answer
Consider the below given C program :#include#includeenum {false, true}...
Understanding the C Program
The provided C program has a specific structure that affects the execution of the print statement. Let's break it down.
Key Components
- Includes and Enum: The program includes standard libraries and defines a simple enum for boolean values.
- Main Function: The execution starts in the `main()` function, where `i` is initialized to 1.
Do-While Loop Mechanics
- Do-While Loop: The `do` block will execute at least once due to its structure, regardless of the condition.
- Print Statement: The program prints the value of `i`, which starts at 1.
Flow of Execution
1. First Iteration:
- `i` is 1.
- The print statement executes, displaying `1`.
- `i` is incremented to 2.
- Since `i` (2) is less than 15, `continue` is executed, which ignores the rest of the loop and jumps back to the `while` condition.
2. While Condition: The condition is `false`, thus the loop does not repeat.
Total Executions of Print Statement
- The print statement executes once (when `i` is 1). After that, the loop ends because the while condition is `false`.
Final Answer
Thus, the correct answer to how many times the print statement is executed is 1 (option 'B').
Explore Courses for GATE exam
Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer?
Question Description
Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer?.
Solutions for Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the below given C program :#include#includeenum {false, true};int main(){int i = 1;do{printf("%d\n", i);i++;if (i < 15)continue;} while (false);getchar();return 0;}How many times the print statement is executed _________.a)2b)1c)4d)3Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev